import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home'
import Dom from '../components/dom/dom'
import Canvas from '../components/canvas/canvas'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Home,
    redirect: '/dom',
    children: [
      { path: '/dom', component: Dom },
      { path: '/canvas', component: Canvas }
    ]
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  // to将要访问的路径 from代表从哪个路径跳转过来 next是一个函数表示放行,传入地址则为强制跳转
  if (to.path === '/dom') return next()
  if (to.path === '/canvas') return next()
  next()
})
export default router
